/**
* @version v 1.2.0 2009/10/19
* @package Nerv Widgets, nw.js
* @subpackage Nerv Toolbar, toolbar.js
* @author Manuele Castellan <manuele.castellan@gmail.com>
*
* @copyright    Copyright (C) Copyright (c) 2009 Manuele Castellan. All rights reserved.
* @license        GNU/GPLv3, see LICENSE
*
*  This program is free software: you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation, either version 3 of the License, or
*  (at your option) any later version.
*
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*
*/


NW3.toolbar = {
	// create a button for toolbar
	Button : function() {
		/* CREO OGGETTO PULSANTE begin */
		var obj = {
			id : null,
			text	: null,                            // nome bottone
			image   : null,                            // icon
			title	: null,                            // titolo bottone
			arrow : null,                              // immagine freccia per popupmenu
			object : null,                             // elemento DIV
			enabled : true,                            // enabled? (true/false)
			active : false,                            // pressed? (false/true)
			status : false,                            // setta stato pulsante
			onclick : false,                           // user onclick
			onmouseover : false,                       // user onmouseover
			onmouseout : false,                        // user onmouseout
			onmousedown : false,                       // user onmousedown
			classprefix : 'NWToolbarCreatorButton',    // prefisso classe
			popup : null                               // array bottoni usati per creare popup
		}
		/* CREO OGGETTO PULSANTE end */
		
		
		/* CREO PULSANTE begin */
		// bottone -- NWToolbarCreatorButton
		var buttonObject = document.createElement("span");
		obj.object = buttonObject;
		
		// creo contenitore -- NWToolbarCreatorButtonConteiner
		//var buttonConteiner = document.createElement('span');
		//buttonObject.appendChild(buttonConteiner);
		
		// creo box -- NWToolbarCreatorButtonBox
		var buttonBox = document.createElement('span');
		buttonObject.appendChild(buttonBox);
		
		// creo image
		var buttonBox_img = document.createElement("img");
		
		// creo text
		var buttonBox_text = document.createElement("span");
		
		// creo arrow bottom
		var buttonBox_img_arrow_bottom = document.createElement("span");
		
		// creo chiusura Bottone
		var buttonBox_close = document.createElement("span");
		/* CREO PULSANTE end */
		
		
		/* SETTO EVENTI PULSANTE begin */
		// attivo eventi
		//var buttonEvents = new NW3.Handling(buttonBox);
		/*var oButtonEvent = new NW3.event.Handling(buttonObject);
		var oButtonBoxEvent = new NW3.event.Handling(buttonBox);
		var oButtonCloseEvent = new NW3.event.Handling(buttonBox_close);*/
		
		/*var oButtonBoxClass = new NW3.rendering(buttonBox);
		var oButtonCloseClass = new NW3.rendering(buttonBox_close);*/
		
		// setto onClick
		NW3.event.addEvent(buttonObject, "click", function(ev){
			// aggiorno grafica stato pulsante
			/*buttonEvents.removeClass(obj.classprefix + "Active");
			buttonEvents.removeClass(obj.classprefix + "Hover");*/
			
			//buttonEvents.stopEvent(NW3.client.isIE() ? window.event : ev);
			
			// eseguo funzione utente
			if(obj.onclick) obj.onclick(obj.id, obj);
		});
		
		// setto mouseover
		NW3.event.addEvent(buttonObject, "mouseover", function(ev){
			//buttonEvents.addClass(obj.classprefix + "Hover");
			NW3.rendering.addClass(buttonBox, obj.classprefix + "BoxOver");
			NW3.rendering.addClass(buttonBox_close, obj.classprefix + "CloseOver");
			NW3.rendering.removeClass(buttonBox, obj.classprefix + "Box");
			NW3.rendering.removeClass(buttonBox_close, obj.classprefix + "Close");
			
			if(obj.active){
				NW3.rendering.removeClass(buttonBox, obj.classprefix + "BoxPressed");
				NW3.rendering.removeClass(buttonBox_close, obj.classprefix + "ClosePressed");
			}
			
			// eseguo funzione utente
			if(obj.onmouseover) obj.onmouseover(obj.id, obj);
		});
		
		// setto mouseout
		NW3.event.addEvent(buttonObject, "mouseout", function(ev){
			NW3.rendering.addClass(buttonBox, obj.classprefix + "Box");
			NW3.rendering.addClass(buttonBox_close, obj.classprefix + "Close");
			NW3.rendering.removeClass(buttonBox, obj.classprefix + "BoxOver");
			NW3.rendering.removeClass(buttonBox_close, obj.classprefix + "CloseOver");
			
			
			if(obj.active){
				NW3.rendering.addClass(buttonBox, obj.classprefix + "BoxPressed");
				NW3.rendering.addClass(buttonBox_close, obj.classprefix + "ClosePressed");
			}
			else{
				NW3.rendering.removeClass(buttonBox, obj.classprefix + "BoxDown");
				NW3.rendering.removeClass(buttonBox_close, obj.classprefix + "CloseDown");
			}
			
			// eseguo funzione utente
			if(obj.onmouseout) obj.onmouseout(obj.id, obj);
		});
		
		// setto mousedown
		NW3.event.addEvent(buttonObject, "mousedown", function(ev){
			NW3.rendering.addClass(buttonBox, obj.classprefix + "BoxDown");
			NW3.rendering.addClass(buttonBox_close, obj.classprefix + "CloseDown");
			
			NW3.event.stopEvent(buttonBox, NW3.client.isIE() ? window.event : ev);
			NW3.event.stopEvent(buttonBox, NW3.client.isIE() ? window.event : ev);
			
			// eseguo funzione utente
			if(obj.onmousedown) obj.onmousedown(obj.id, obj);
		});
		
		NW3.event.addEvent(buttonObject, 'mouseup', function(){
			NW3.rendering.addClass(buttonBox, obj.classprefix + "BoxOver");
			NW3.rendering.addClass(buttonBox_close, obj.classprefix + "CloseOver");
			
			NW3.rendering.removeClass(buttonBox, obj.classprefix + "BoxDown");
			NW3.rendering.removeClass(buttonBox_close, obj.classprefix + "CloseDown");
		});
		/* SETTO EVENTI PULSANTE end */
		
		
		/* METODI */
		// recupera stato bottone
		obj.getStatus = function(){
			return obj.active;
		}
		
		// funzione che cambia lo stato del bottone
		obj.setStatus = function(op){
			switch(op){
				case "enabled":
					NW3.rendering.removeClass(buttonBox, obj.classprefix + "BoxDisabled");
					NW3.rendering.removeClass(buttonBox_close, obj.classprefix + "CloseDisabled");
					
					NW3.rendering.removeClass(buttonBox, obj.classprefix + "BoxPressed");
					NW3.rendering.removeClass(buttonBox_close, obj.classprefix + "ClosePressed");
					
					NW3.rendering.addClass(buttonBox, obj.classprefix + "Box");
					NW3.rendering.addClass(buttonBox_close, obj.classprefix + "Close");
					
					obj.active = false;
					break;
				case "disabled":
					NW3.rendering.removeClass(buttonBox, obj.classprefix + "BoxPressed");
					NW3.rendering.removeClass(buttonBox_close, obj.classprefix + "ClosePressed");
					
					NW3.rendering.addClass(buttonBox, obj.classprefix + "BoxDisabled");
					NW3.rendering.addClass(buttonBox_close, obj.classprefix + "CloseDisabled");
					
					break;
				case "pressed":
					NW3.rendering.removeClass(buttonBox, obj.classprefix + "BoxDisabled");
					NW3.rendering.removeClass(buttonBox_close, obj.classprefix + "CloseDisabled");
					
					NW3.rendering.addClass(buttonBox, obj.classprefix + "BoxPressed");
					NW3.rendering.addClass(buttonBox_close, obj.classprefix + "ClosePressed");
					
					obj.active = true;
					break;
			}
		}
		
		// aggiungi bottone popup
		obj.addPopupButton = function(val){
			if( (val != '') && (val != 'undefined') && (val != null) ){
				obj.popup = val;
			}
		}
		
		// setta classe per pulsante
		obj.setClass = function(val){
			if( (val != '') && (val != 'undefined') && (val != null) ){
				buttonBox.className = val;
				obj.classprefix = val;
			}
		}
		
		// setto freccia del pulsante per popup
		obj.setArrow = function(val){
			if(val){
				obj.arrow = val;
			}
			else obj.arrow = false;
		}
		
		// setta id del bottone
		obj.setId = function(val){
			obj.id = val;
		}
		
		// setta il titolo
		obj.setTitle = function(val){
			if(val != ''){
				obj.title = val;
				buttonBox.title = val;
			}
		}
		
		// setta il testo
		obj.setText = function(val){
			if(val != ''){
				obj.text = val;
			}
		}
		
		// setta immagine
		obj.setImage = function(val){
			if(val != ''){
				obj.image = val;
			}
		}
		
		// setta onclick
		obj.onClick = function(val){
			if(val != ''){
				obj.onclick = val;
			}
		}
		
		// setta onmouseover
		obj.onMouseOver = function(val){
			if(val != ''){
				obj.onmouseover = val;
			}
		}
		
		// setta onmouseout
		obj.onMouseOut = function(val){
			if(val != ''){
				obj.onmouseout = val;
			}
		}
		
		// setta onmousedown
		obj.onMouseDown = function(val){
			if(val != ''){
				obj.onmousedown = val;
			}
		}
		
		// restituisce l'oggetto
		obj.output = function(){
			// setto classi
			buttonBox.className = obj.classprefix + 'Box';
			//buttonConteiner.className = obj.classprefix + 'Conteiner';
			buttonObject.className = obj.classprefix;
			
			// chiusura bottone
			buttonBox_close.className = obj.classprefix + 'Close';
			buttonBox.appendChild(buttonBox_close);
			
			
			if(obj.popup) obj.setArrow(true);
			
			// image
			if(obj.image){
				buttonBox_img.src = obj.image;
				buttonBox_img.className = obj.classprefix + 'Img';
				buttonBox_close.appendChild(buttonBox_img);
			}
			
			// text
			if(obj.text){
				buttonBox_text.appendChild(document.createTextNode(obj.text));
				// setto un padding per spaziare immagine e testo
				buttonBox_img.style.marginRight = '5px';
				
				buttonBox_text.className = obj.classprefix + 'Label';
				buttonBox_close.appendChild(buttonBox_text);
			}
			
			// arrow bottom
			if(obj.arrow){
				buttonBox_img_arrow_bottom.className = obj.classprefix + 'Arrow';
				buttonBox_close.appendChild(buttonBox_img_arrow_bottom);
			}
			
			/*// chiusura bottone
			buttonBox_close.className = obj.classprefix + 'Close';
			buttonBox.appendChild(buttonBox_close);*/
			
			
			// crea menu popup
			if(obj.popup){
				// visualizzo il popup al click del bottone
				obj.onMouseOver(function(){
					// attivo freccia
					obj.setArrow(true);
					//if(obj.text == 'Apri') alert(buttonObject.parentNode.offsetWidth);
					//buttonBox.style.width = buttonObject.parentNode.offsetWidth;
					// setto position top e left per popup
					obj.popup.setTop(buttonObject.offsetTop);
					obj.popup.setLeft(buttonObject.parentNode.offsetWidth - 6);
					obj.popup.show();
				});
				
				obj.onMouseOut(function(){
					// attivo freccia
					//obj.setArrow(true);
					//if(obj.text == 'Apri') alert(buttonObject.parentNode.offsetWidth);
					//buttonBox.style.width = buttonObject.parentNode.offsetWidth;
					// setto position top e left per popup
					//obj.popup.setTop(buttonObject.offsetTop);
					//obj.popup.setLeft(buttonObject.parentNode.offsetWidth - 4);
					obj.popup.hide();
				});
				
				// aggiungo al conteiner
				buttonObject.appendChild(obj.popup.output());
			}
			
			return obj.object = buttonObject;
		}
		
		return obj;
	},
	
	Label : function(){
		var oSpan = document.createElement('span');
		
		var obj = {
			object	:	oSpan,
			text	:	null,
			width	:	null,
			classprefix : 'NWToolbarCreatorLabel'
		}
		
		obj.setClass = function(val){
			if(val){
				obj.classprefix = val;
			}
			obj.object.className = obj.classprefix;
		}
		
		obj.setText = function(val){
			if(val){
				obj.text = val;
			}
			obj.object.innerHTML = obj.text;
		}
		
		obj.output = function(){
			obj.setClass();
			
			return obj.object;
		}
		
		return obj;
	},
	
	// popup
	Popup : function(){
		// popup object
		var obj = {
			id : null,      // identificativo oggetto
			object : null   // elemento DIV
		}
		
		popupClass = 'NWPopupCreator';
		popupClassButton = popupClass + 'Button';
		popupClassButtonSeparator = popupClass + 'Separator'
		
		// creo menu popup
		var menuPopup = document.createElement('div');
		menuPopup.style.position = 'absolute';
		menuPopup.style.display = 'none';
		
		// creo array bottoni
		obj.buttons = new Array();
		
		//menuPopup.id = '';
		menuPopup.className = popupClass;
		obj.object = menuPopup;
		
		var menuPopupEvents = new NW3.event.Handling(menuPopup);
		// setto mouseover
		menuPopupEvents.addEvent("mouseover", function(ev){
			obj.show();
		});
		
		// setto mouseout
		menuPopupEvents.addEvent("mouseout", function(ev){
			obj.hide();
		});
		
		// aggiunge bottone alla toolbar
		obj.addButton = function(obj){
			// setto stato pulsante (ma non va)
			/*obj.onMouseOver(function(){
				obj.status('pressed');
			});
			obj.onMouseOut(function(){
				obj.status('enabled');
			});*/
			
			obj.setClass(popupClassButton);
			menuPopup.appendChild(obj.output());
		}
		
		// aggiunge separatore
		obj.addSeparator = function(){
			var popupSeparator = document.createElement('div');
			popupSeparator.className = popupClassButtonSeparator;
			
			menuPopup.appendChild(popupSeparator);
		}
		
		// visualizza menu
		obj.show = function(){
			menuPopup.style.display = 'block';
		}
		
		// nascondi menu
		obj.hide = function(){
			menuPopup.style.display = 'none';
		}
		
		// setta style.top
		obj.setTop = function(val){
			menuPopup.style.top = val + 'px';
		}
		
		// setta style.left
		obj.setLeft = function(val){
			menuPopup.style.left = val + 'px';
		}
		
		
		// setta style.width
		obj.setWith = function(val){
			menuPopup.style.width = val + 'px';
		}
		
		// setta style.height
		obj.setHeight = function(val){
			menuPopup.style.height = val + 'px';
		}
		
		// stampa popup
		obj.print = function(){
			NW3.core.object.print(obj.output());
		}
		
		obj.replace = function(targetElement){
			NW3.core.object.replace(targetElement, obj.output());
		};
		
		obj.insertAfter = function(targetElement){
			NW3.core.object.insertAfter(obj.output(), targetElement);
		};
		
		obj.insertBefore = function(targetElement){
			NW3.core.object.insertBefore(obj.output(), targetElement);
		};
		
		obj.appendChild = function(targetElement){
			NW3.core.object.appendChild(obj.output(), targetElement);
		};
		
		// restituisce l'oggetto
		obj.output = function(){
			return obj.object;
		}
		
		return obj;
	},
	
	// menu
	Menu : function(){
		// menu object
		var obj = {
			object : null,  // elemento DIV
			active : null,	// button pressed
			buttons : null  // array bottoni
		}
		
		
		menuClass = 'NWToolbarCreator';
		menuClassButton = menuClass + 'Button';
		menuClassTable = menuClass + 'Table';
		//menuClassButtonSeparator = menuClass + 'Separator'
		
		// creo menu toolbar
		var menuObject = document.createElement('div');
		//menuObject.style.position = 'absolute';
		//menuObject.style.display = 'none';
		
		// creo array bottoni
		obj.buttons = new Array();
		
		//menuObject.id = '';
		menuObject.className = menuClass;
		//obj.object = menuObject;
		
		obj.setPressed = function(val){
			val--;
			if(NW3.core.string.isInt(val)) obj.active = val;
			obj.update(val);
		}
		
		// aggiorna stato pulsanti toolbar
		obj.update = function(id){
			for(i=0; i<obj.buttons.length; i++){
				if(obj.buttons[i].id == id){
					obj.buttons[i].setStatus('pressed');
				}
				else{
					obj.buttons[i].setStatus('enabled');
				}
			}
		}
		
		var toolbar_table = document.createElement("table");
		toolbar_table.border = "0px";
		toolbar_table.cellSpacing = "0px";
		toolbar_table.cellPadding = "0px";
		toolbar_table.className = menuClassTable;
		
		// required for IE
		var tb_body = document.createElement("tbody");
		toolbar_table.appendChild(tb_body);
		tb_row = document.createElement("tr");
		tb_body.appendChild(tb_row);
		
		/*var tb_cell = document.createElement("td");
		//tb_cell.className = "NWToolbarCreatorBegin";
		tb_cell.unselectable = "1";
		tb_row.appendChild(tb_cell);
		tb_body.appendChild(tb_row);*/
		
		obj.object = toolbar_table;
		
		/*// setto mouseout
		menuObjectEvents.addEvent("mouseout", function(ev){
			menu.hide();
		});*/
		
		var bCounter = 0;
		
		// aggiunge bottone alla toolbar
		obj.addButton = function(oButton){
			
			// setto stato pulsante (ma non va)
			/*obj.onMouseOver(function(){
				obj.status('pressed');
			});
			obj.onMouseOut(function(){
				obj.status('enabled');
			});*/
			
			tb_cell = document.createElement("td");
			
			obj.buttons.push(oButton);
			
			oButton.setId(bCounter);
			
			// setto classe
			oButton.setClass(menuClassButton);
			// setto onMouseDown
			oButton.onMouseDown(function(id){
				obj.update(id);
			});
			tb_cell.appendChild(oButton.output());
			tb_row.appendChild(tb_cell);
			
			bCounter++;
		}
		
		/*// aggiunge separatore
		menu.addSeparator = function(){
			var menuSeparator = document.createElement('div');
			menuSeparator.className = menuClassButtonSeparator;
			
			menuObject.appendChild(menuSeparator);
		}*/
		
		/*// visualizza menu
		menu.show = function(){
			menuObject.style.display = 'block';
		}
		
		// nascondi menu
		menu.hide = function(){
			menuObject.style.display = 'none';
		}
		
		// setta style.top
		menu.setTop = function(val){
			menuObject.style.top = val + 'px';
		}
		
		// setta style.left
		menu.setLeft = function(val){
			menuObject.style.left = val + 'px';
		}*/
		
		// restituisce l'oggetto
		obj.output = function(){
			return obj.object;
		}
		
		obj.print = function(){
			NW3.core.object.print(obj.output());
		}
		
		obj.replace = function(targetElement){
			NW3.core.object.replace(targetElement, obj.output());
		};
		
		obj.insertAfter = function(targetElement){
			NW3.core.object.insertAfter(obj.output(), targetElement);
		};
		
		obj.insertBefore = function(targetElement){
			NW3.core.object.insertBefore(obj.output(), targetElement);
		};
		
		obj.appendChild = function(targetElement){
			NW3.core.object.appendChild(obj.output(), targetElement);
		};
		
		return obj;
	},
	
	// toolbar
	Toolbar : function(params){
		// creo array bottoni
		this.buttons = new Array();
		// creo array popup
		this.popups = new Array();
		// creo array separators
		this.separators = new Array();
		// creo array menu
		this.menu = new Array();
		// creo checkbox
		this.checkbox = new Array();
		// begin
		this.begin = null;
		// object container
		this.oContainer = document.createElement('div');
		
		// contatore numero bottoni
		var bCounter = 0;
		
		// create a new line in the toolbar
		newLine = function(begin) {
			var toolbar_table = document.createElement("table");
			toolbar_table.border = "0px";
			toolbar_table.cellSpacing = "0px";
			toolbar_table.cellPadding = "0px";
			toolbar_table.className = "NWToolbarCreatorTable";
			
			// required for IE
			var tb_body = document.createElement("tbody");
			toolbar_table.appendChild(tb_body);
			tb_row = document.createElement("tr");
			tb_body.appendChild(tb_row);
			
			if(begin){
				var tb_cell = document.createElement("td");
				tb_cell.className = "NWToolbarCreatorBegin";
				tb_cell.unselectable = "1";
				tb_row.appendChild(tb_cell);
			}
			tb_body.appendChild(tb_row);
			
			return toolbar_table;
		}
		
		this.setBegin = function(val){
			if(val) this.begin = true;
			else  this.begin = false;
		}
		
		// aggiungo bottone alla toolbar
		this.addButton = function(oButton, oPopup){
			// setto id bottone
			//oButton.setId(bCounter);
			// aggiungo bottone all'array della toolbar
			this.buttons[bCounter] = oButton;
			
			if(oPopup){
				// setto button arrow
				oButton.setArrow(true);
				// setto popup
				this.popups[bCounter] = oPopup;
			}
			
			bCounter++;
		}
		
		/* aggiunge menu */
		this.newMenu = function(arr){
			if(arr.buttons.length > 0){
				var menuButt = new NW3.toolbar.Menu();
				for(i=0;arr.buttons.length>=i;i++){
					if(arr.buttons[i] != undefined){
						var butt = new NW3.toolbar.Button();
						butt.setImage(arr.buttons[i].image);
						butt.setTitle(arr.buttons[i].title);
						butt.setText(arr.buttons[i].text);
						butt.onClick(arr.buttons[i].onclick);
						
						menuButt.addButton(butt);
					}
				}
				
				if(arr.pressed){
					menuButt.setPressed(arr.pressed);
				}
				
				this.addMenuButton(menuButt);
			}
		}
		
		// setta width toolbar
		this.setWidth = function(val){
			if(NW3.core.string.isInt(val)){
				this.width = val;
				this.oContainer.style.width = val + 'px';
			}
		}
		
		// aggiungo bottone checkbox
		this.addCheckbox = function(oCheckbox){
			// aggiungo bottone checkbox all'array
			this.checkbox[bCounter] = oCheckbox;
			
			oCheckbox.onMouseDown(function(){
				if(oCheckbox.getStatus() == false){
					oCheckbox.setStatus('pressed');
				}
				else{
					oCheckbox.setStatus('enabled');
				}
			});
			
			bCounter++;
		}
		
		// aggiungo menu bottone alla toolbar
		this.addMenuButton = function(oMenu){
			// aggiungo menu bottone all'array
			this.menu[bCounter] = oMenu;
			
			bCounter++;
		}
		
		this.newButton = function(params){
			if(params){
				var butt = new NW3.toolbar.Button();
				butt.setText(params.text);
				butt.setTitle(params.title);
				butt.setImage(params.image);
				butt.onClick(params.onclick);
				
				if(params.type == 'checkbox') this.addCheckbox(butt);
				else this.addButton(butt);
			}
		}
		
		// aggiunge separatore
		this.addSeparator = function(){
			var toolbarSeparator = document.createElement('div');
			
			this.separators[bCounter] = toolbarSeparator;
			bCounter++;
		}
		this.newSeparator = this.addSeparator;
		
		// crea toolbar
		this.output = function(){
			// creo linea
			var line = new newLine(this.begin);
			
			// recupero bottoni
			for(i = 0; i < bCounter; i++) {
				// buttons
				var td_dom_object = document.createElement("td");
				td_dom_object.unselectable = "1";
				
				if(this.buttons[i]){
					//this.buttons[i].setClass('NWToolbarCreatorButton');
					var oButton = this.buttons[i].output();
					td_dom_object.appendChild(oButton);
					
					// popups
					if(this.popups[i]){
						var popup_tmp = this.popups[i];
						this.buttons[i].onClick(function(){
							// setto posizione popup
							popup_tmp.setTop(oButton.offsetHeight);
							// visualizzo il popup al click del bottone
							popup_tmp.show();
						});
						
						
						/*this.buttons[i].onMouseOver(function(){
							this.buttons[i].status('Pressed');
						});
						this.buttons[i].onMouseOut(function(){
							// visualizzo il popup al click del bottone
							popup_tmp.show();
						});*/
						
						td_dom_object.appendChild(this.popups[i].output());
					}
				}
				
				if(this.menu[i]){
					var oMenu = this.menu[i].output();
					td_dom_object.appendChild(oMenu);
				}
				
				if(this.checkbox[i]){
					var oCheckbox = this.checkbox[i].output();
					td_dom_object.appendChild(oCheckbox);
				}
				
				// appendo oggetti dentro alla linea
				line.firstChild.firstChild.appendChild(td_dom_object);
				
				// separators
				if(this.separators[i]){
					td_dom_object_separator = document.createElement("td");
					var separators_tmp = this.separators[i];
					separators_tmp.className = 'NWToolbarCreatorSeparator';
					td_dom_object_separator.appendChild(this.separators[i]);
					
					// appendo oggetti dentro alla linea
					line.firstChild.firstChild.appendChild(td_dom_object_separator);
				}
			}
			
			// creo oggetto esterno
			this.oContainer.className = 'NWToolbarCreatorBackground';
			this.oContainer.unselectable = "1";
			
			// appendo toolbar
			var toolbarDiv = document.createElement('div');
			toolbarDiv.className = 'NWToolbarCreator';
			toolbarDiv.appendChild(line);
			toolbarDiv.unselectable = "1";
			this.oContainer.appendChild(toolbarDiv);
			
			if(params != undefined && params.width) this.setWidth(params.width);
			
			return this.oContainer;
		};
		
		// stampa toolbar
		this.print = function(){
			NW3.core.object.print(this.output());
		};
		
		this.replace = function(targetElement){
			NW3.core.object.replace(targetElement, this.output());
		};
		
		this.insertAfter = function(targetElement){
			NW3.core.object.insertAfter(this.output(), targetElement);
		};
		
		this.insertBefore = function(targetElement){
			NW3.core.object.insertBefore(this.output(), targetElement);
		};
		
		this.appendChild = function(targetElement){
			NW3.core.object.appendChild(this.output(), targetElement);
		};
	}
};